package com.ericsson.enap.modules.ossalarm.service.impl;

import com.ericsson.enap.modules.ossalarm.mapper.VgcEnmAlarmMapper;
import com.ericsson.enap.modules.ossalarm.service.VgcEnmAlarmService;
import com.ericsson.enap.modules.ossalarm.thread.VgcEnmDealAlarmThread;
import com.ericsson.enap.modules.ossalarm.thread.VgcEnmReadAlarmThread;
import com.ericsson.enap.modules.sys.entity.EnipNetelement;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Collectors;

@Component
public class VgcEnmAlarmServiceImpl implements VgcEnmAlarmService {
    @Autowired
    private VgcEnmAlarmMapper vgcEnmAlarmMapper;

    public List<EnipNetelement> queryNetelementList(){
        return vgcEnmAlarmMapper.queryEnipNetelementList();
    }

    @Override
    public void readAndDealAlarm(List<EnipNetelement> netElements, Logger log) {
        LinkedBlockingQueue msgQueue=new LinkedBlockingQueue();
        Map<String,EnipNetelement> netElementMap=netElements.stream().collect(Collectors.toMap(EnipNetelement::getFdn, EnipNetelement->EnipNetelement));
        VgcEnmReadAlarmThread ossReadAlarmThread=new VgcEnmReadAlarmThread(netElementMap,msgQueue,log);
        VgcEnmDealAlarmThread ossDealAlarmThread=new VgcEnmDealAlarmThread(vgcEnmAlarmMapper,netElementMap,msgQueue,log);
        ossReadAlarmThread.start();
        ossDealAlarmThread.start();
    }
}
